package com.example.cachecontroldemo;

import com.example.cachecontroldemo.interceptor.AbstractCacheControlValidator;
import com.example.cachecontroldemo.interceptor.CacheValidatorInterceptor;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Map;

@Component
@RequiredArgsConstructor
public class InterceptorConfig implements WebMvcConfigurer {

    /**
     * 容易会自动收集AbstractCacheControlValidator的子类，装载到cacheControlValidators集合内
     */
    private final Map<String, AbstractCacheControlValidator> cacheControlValidators;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new CacheValidatorInterceptor(cacheControlValidators))
                .addPathPatterns("/**");

    }

}